import { createRouter, createWebHistory } from 'vue-router';
import Home from '../components/home.vue';
import Login from '../components/login/login.vue';
import Register from '../components/login/register.vue';
import Forgetpwd from '../components/login/forgetpwd.vue';
import Starter from '../components/starter.vue';

import MaintenanceServiceRecord from '../components/maintenance_control/MaintenanceServiceRecord.vue';
import CreateRepairOrder from '../components/maintenance_control/repairreport/CreateRepairOrder.vue';
import manufactureCodeDetail from '../components/maintenance_control/repairreport/manufactureCodeDetail.vue';
import RepairOrderQuery from '../components/maintenance_control/repairreport/RepairOrderQuery.vue';
import MyOrders from '@/components/personalcenter/MyOrders.vue';
import Dispatch from '@/components/maintenance_control/Dispatch.vue';
import OrderTaking from '@/components/maintenance_control/OrderTaking.vue';
import Reassignment from '@/components/maintenance_control/Reassignment.vue';
import CheckorderReassignment from '@/components/maintenance_control/maintaincheckorder/CheckorderReassignment.vue';
import RepairOrderQueryList from '@/components/maintenance_control/repairreport/RepairOrderQueryList.vue';
import CreateOrderSubmit from '@/components/maintenance_control/repairreport/CreateOrderSubmit.vue';
import StaffHomeView from '@/components/maintenance_control/StaffOrder/StaffOrderHomeView.vue';
import ProductIndex from '@/components/product/ProductIndex.vue';
import ProductList from '@/components/product/ProductList.vue';
import ProductDetail from '@/components/product/ProductDetail.vue';
import QrUnbind from '@/components/product/QRUnbind.vue';
import QrDeprecate from '@/components/product/QRDeleted.vue';
import deviceView from '@/components/deviceview/deviceView.vue';
import device from '@/components/deviceview/device.vue';
import deviceAlarmMore from '@/components/deviceview/manage/deviceAlarmMore.vue';
import DeviceMaintainCheckDetail from '@/components/maintenance_control/DeviceMatainCheckDetail/DeviceMaintainCheckDetail.vue';
import workbench from '@/components/workbench/workbench.vue';
import customerManage from '@/components/workbench/maintaincheckcustomer/customerManage.vue';
import newCustomer from '@/components/workbench/maintaincheckcustomer/newCustomer.vue';
import customerDetail from '@/components/workbench/maintaincheckcustomer/customerDetail.vue';

import { selfI18n } from '@/i18n';

const routes = [
    {
        path: '/login',
        name: 'Login',
        meta: { title: selfI18n('wp_Log_in') },
        component: Login

    },
    {
        path: '/register',
        name: 'Register',
        meta: { title: selfI18n('wp_register') },
        component: Register

    },
    {
        path: '/forgetpwd',
        name: 'Forgetpwd',
        meta: { title: selfI18n('forget_password') },
        component: Forgetpwd

    },
    {
        path: '/starter',
        name: 'Starter',
        component: Starter
    },
    {
        path: '/home',
        name: 'Home',
        component: Home,
        redirect: '/staff/maintenancelist'
    }, {
        // 新建报修
        path: '/createrepairorder',
        name: 'createrepairorder',
        component: CreateRepairOrder,
        meta: { title: selfI18n('wp_New_Repair') }
    }, {
        // 报修码详情
        path: '/manufactureCodeDetail',
        name: 'manufactureCodeDetail',
        component: manufactureCodeDetail,
        meta: { title: selfI18n('wp-bao-xiu-ma') }
    }, {
        // 编辑报修详情
        path: '/editrepairorder',
        name: 'editrepairorder',
        // component: CreateRepairOrder,
        meta: { title: selfI18n('wp-bian-ji-xiang-qing') },
        component: () => import('@/components/maintenance_control/repairreport/EditRepairOrder.vue')
    }, {
        // 报修查询
        path: '/repairorderquery',
        name: 'repairorderquery',
        component: RepairOrderQuery,
        meta: { title: selfI18n('wp_Repair_Inquiry') }
    }, {
        // 服务记录填写
        path: '/maintenanceservicerecord',
        name: 'maintenanceservicerecord',
        component: MaintenanceServiceRecord,
        meta: {
            title: selfI18n('wp_Service_Record')
            // requireAuth: true,
            // roles: ['maintainadmin', 'maintainer']
        }
    }, {
        path: '/maitenanceorderdetail/:repairId',
        name: 'maitenanceorderdetail',
        props: true,
        meta: {
            requireAuth: false,
            title: selfI18n('gong-dan-xiang-qing')
        },
        component: () => import('@/components/maintenance_control/MaintenanceOrderDetail/MaintenanceOrderDetail.vue')
    }, {
        path: '/MaintenanceOrderDetailWithoutButton/:repairId',
        name: 'MaintenanceOrderDetailWithoutButton',
        props: true,
        meta: {
            requireAuth: false,
            title: selfI18n('gong-dan-xiang-qing')
        },
        component: () => import('@/components/maintenance_control/MaintenanceOrderDetail/MaintenanceOrderDetailWithoutButton.vue')
    }, {
        path: '/maitenancecheckorderdetail/:maintainworkorderid',
        name: 'maitenancecheckorderdetail',
        props: true,
        meta: {
            requireAuth: true,
            title: selfI18n('wp-wei-jian-xiang-qing'),
            roles: ['maintainadmin', 'maintainer']
        },
        component: () => import('@/components/maintenance_control/maintaincheckorder/MaintenancecheckOrderDetail.vue')
    }, {
        path: '/maintaincheckorderrecord',
        name: 'maintaincheckorderrecord',
        props: true,
        meta: {
            requireAuth: false,
            title: selfI18n('wp-wei-jian-ji-lu'),
            roles: ['maintainadmin', 'maintainer']
        },
        component: () => import('@/components/maintenance_control/maintaincheckorderrecord/MaintaincheckOrderRecord.vue')
    }, {
        path: '/checkordersuccess',
        name: 'checkordersuccess',
        props: true,
        meta: {
            requireAuth: false,
            title: selfI18n('wp-yi-jie-dan'),
            roles: ['maintainadmin', 'maintainer']
        },
        component: () => import('@/components/maintenance_control/maintaincheckorderrecord/checkOrderSuccess.vue')
    },
    { // 内部员工、管理员用户评价
        path: '/CustomerRatingInside/:repairId/:repairPhone?',
        name: 'CustomerRatingInside',
        props: true,
        meta: { requireAuth: false },
        component: () => import('@/components/maintenance_control/CustomerOrder/CustomerRatingInside.vue')
    },
    { // 用户评价
        path: '/customerrating/:repairId/:repairPhone?',
        name: 'CustomerRating',
        props: true,
        meta: { requireAuth: false },
        component: () => import('@/components/maintenance_control/CustomerOrder/CustomerRating.vue')
    },
    { // 用户通过手机验证码评价
        path: '/customerRatingByCode/:repairId',
        name: 'customerRatingByCode',
        props: true,
        meta: { requireAuth: false },
        component: () => import('@/components/maintenance_control/CustomerOrder/CustomerRatingByPhone.vue')
    },
    { // 评价成功
        path: '/RateSuccess/:repairId',
        name: 'RateSuccess',
        props: true,
        meta: { requireAuth: false },
        component: () => import('@/components/maintenance_control/CustomerOrder/RateSuccess.vue')
    },
    {
        // 我的工单
        path: '/myorders',
        name: 'myorders',
        component: MyOrders,
        meta: {
            title: selfI18n('wp_My_Order'),
            requireAuth: true,
            roles: ['maintainadmin', 'maintainer']
        }
    },
    {
        path: '/messagelist',
        name: 'MessageList',
        meta: {
            title: selfI18n('wp_Message_List'),
            requireAuth: true,
            roles: ['maintainadmin', 'maintainer']
        },
        component: () => import('@/components/message/MessageList.vue')
    },
    {
        path: '/staff',
        name: 'staff',
        component: StaffHomeView,
        meta: {
            roles: ['maintainadmin', 'maintainer']
        },
        children: [
            {

                path: 'maintenancelist',
                name: 'maintenancelist',
                meta: {
                    title: selfI18n('wp-gong-dan'),
                    keepAlive: true,
                    requireAuth: true
                },
                component: () => import('@/components/maintenance_control/StaffOrder/StaffOrderListView.vue')
            },
            {

                path: 'checkin',
                name: 'checkin',
                meta: {
                    title: selfI18n('wp_Check_in'),
                    requireAuth: true
                },
                component: () => import('@/components/clockin/ClockinCenter.vue')
            },
            {
                path: 'personalcenter',
                name: 'personalcenter',
                component: () => import('@/components/personalcenter/Index.vue'),
                meta: {
                    title: selfI18n('My'),
                    requireAuth: true
                }
            }, {
                path: 'device',
                name: 'device',
                component: device,
                meta: {
                    title: selfI18n('wp-she-bei'),
                    requireAuth: true
                }
            }, {
                path: 'workbench',
                name: 'workbench',
                component: workbench,
                meta: {
                    title: selfI18n('wp-gong-zuo-tai'),
                    requireAuth: true
                }
            }
        ]
    },
    {
        // 报修派工
        path: '/dispatch/:repairId/:company?',
        name: 'dispatch',
        props: true,
        meta: {
            title: selfI18n('wp_Dispatch_RR'),
            requireAuth: true,
            roles: ['maintainadmin', 'maintainer']
        },
        component: Dispatch
    },
    {
        // 报修接单
        path: '/ordertaking/:repairId/:company?',
        name: 'ordertaking',
        props: true,
        meta: {
            title: selfI18n('wp_Accept_RR'),
            requireAuth: true,
            roles: ['maintainadmin', 'maintainer']
        },
        component: OrderTaking
    },
    {
        // 报修单转派
        path: '/reassignment/:repairId',
        name: 'reassignment',
        meta: {
            title: selfI18n('wp_Reservation_Form_Transfer'),
            requireAuth: true,
            roles: ['maintainadmin', 'maintainer']
        },
        props: route => ({
            repairId: route.params.repairId,
            company: route.query.company,
            administrator: route.query.administrator,
            administratoralias: route.query.administratoralias
        }),
        component: Reassignment
    },
    {
        // 维检工单转派
        path: '/checkorderreassignment/:maintainworkorderid',
        name: 'checkorderreassignment',
        meta: {
            title: selfI18n('wp-wei-jian-gong-dan-zhuan-pai'),
            requireAuth: true,
            roles: ['maintainadmin', 'maintainer']
        },
        props: route => ({
            maintainworkorderid: route.params.maintainworkorderid,
            // company: route.query.company,
            administrator: route.query.administrator,
            administratoralias: route.query.administratoralias
        }),
        component: CheckorderReassignment
    },
    {
        path: '/repairorderquerylist',
        name: 'repairorderquerylist',
        component: RepairOrderQueryList,
        meta: { title: selfI18n('wp_Query_result_of_Repair_request') }
    },
    {
        path: '/createordersubmit',
        name: 'createordersubmit',
        component: CreateOrderSubmit,
        meta: { title: selfI18n('wp_New_Repair') }
    }, {
        path: '/productindex',
        name: 'ProductIndex',
        component: ProductIndex,
        meta: { title: selfI18n('shou-ye') }
    }, {
        path: '/productlist',
        name: 'ProductList',
        component: ProductList,
        meta: { title: selfI18n('chan-pin-zong-lan') }
    }, {
        path: '/productdetail',
        name: 'ProductDetail',
        component: ProductDetail,
        meta: { title: selfI18n('chan-pin-xiang-qing') }
    }, {
        path: '/qrunbind',
        name: 'QrUnbind',
        component: QrUnbind,
        meta: { title: selfI18n('er-wei-ma') }
    }, {
        path: '/qrdeprecate',
        name: 'QrDeprecate',
        component: QrDeprecate,
        meta: { title: selfI18n('er-wei-ma') }
    }, {
        path: '/deviceView',
        name: 'deviceView',
        component: deviceView,
        meta: { title: selfI18n('wp-she-bei-xiang-qing') }
    }, {
        path: '/deviceAlarmMore',
        name: 'deviceAlarmMore',
        component: deviceAlarmMore,
        meta: { title: selfI18n('wp-she-bei-bao-jing') }
    }, {
        path: '/DeviceMaintainCheckDetail',
        name: 'DeviceMaintainCheckDetail',
        component: DeviceMaintainCheckDetail,
        meta: { title: selfI18n('wp-she-bei-dian-jian') }
    }, {
        path: '/customerManage',
        name: 'customerManage',
        component: customerManage,
        requireAuth: true,
        meta: { title: selfI18n('wp-ke-hu-guan-li') }
    }, {
        path: '/newCustomer',
        name: 'newCustomer',
        component: newCustomer,
        requireAuth: true,
        meta: { title: selfI18n('wp-xin-jian-ke-hu') }
    }, {
        path: '/customerDetail',
        name: 'customerDetail',
        component: customerDetail,
        requireAuth: true,
        meta: { title: selfI18n('wp-ke-hu-xiang-qing') }
    }
];

const getPublicPath = () => {
    if (process.env.NODE_ENV === 'production') {
        return '/weibaoapp/';
    }
    return '/';
};

const router = createRouter({
    history: createWebHistory(getPublicPath()),
    routes
});

export default router;
